package com.ctsig.docker.controller;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Date;

/**
 * 测试
 *
 * @author stephen.shen
 * @email shenzhaoxiang@gmail.com
 * @date 2020-06-12 10:30
 */
@RestController
public class TestController {

    @Value("${spring.application.name}")
    String name;

    @Value("${spring.profiles.active}")
    String env;

    @GetMapping("/env")
    public String currentEnv() {
        return name + "=>" + env + ", Date: " + new Date();
    }


    @GetMapping("/ip")
    public String currentTime() {
        return "IP: " + getServiceIp() + ", Date: " + new Date();
    }

    public String getServiceIp() {
        String ip = null;
        try {
            InetAddress address = InetAddress.getLocalHost();
            ip = address.getHostAddress();
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
        return ip;
    }
}
